import 'dart:math';

import 'package:amoy_ticket/people/cinema_ticket/cinema_ticket_logic.dart';
import 'package:amoy_ticket/utils/dashed_rect.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/instance_manager.dart';
import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart';

class CinemaTicketPage extends StatefulWidget {
  CinemaTicketPage({Key? key}) : super(key: key);

  @override
  State<CinemaTicketPage> createState() => _CinemaTicketPageState();
}

class _CinemaTicketPageState extends State<CinemaTicketPage> {
  final logic = Get.put(CinemaTicketLogic());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('我的电影票')),
      backgroundColor: Color(0xFFf5f6f8),
      body: SmartRefresher(
        enablePullUp: true,
        onRefresh: () async {
          await Future.delayed(Duration(milliseconds: 1000));
          logic.refreshController.refreshCompleted();
        },
        onLoading: () async {
          await Future.delayed(Duration(milliseconds: 1000));
          logic.refreshController.loadNoData();
        },
        controller: logic.refreshController,
        child: ListView.builder(
          itemCount: logic.myCinemaTicketList.length,
          itemBuilder: (BuildContext context, int i) {
            return item(
              logic.myCinemaTicketList[i]['name'],
              logic.myCinemaTicketList[i]['num'],
              logic.myCinemaTicketList[i]['time'],
              logic.myCinemaTicketList[i]['location'],
            );
          },
        ),
      ),
    );
  }

  Widget item(String name, String num, String time, String location) {
    return Container(
      height: 110.w,
      margin: EdgeInsets.only(top: 20.w),
      child: Row(
        children: [
          Container(
            height: 110.h,
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.only(
                topRight: Radius.circular(10.r),
                bottomRight: Radius.circular(10.r),
              ),
            ),
            width: 50.w,
            child: Center(
              child: CircleAvatar(
                radius: 15.r,
                backgroundColor: Color(0xFFced1d5),
                child: Text('座',
                    style: TextStyle(color: Colors.white, fontSize: 16.sp)),
              ),
            ),
          ),
          Container(
            height: 90.h,
            child: DashedRect(
              color: Colors.grey,
              strokeWidth: 1,
              gap: 4,
            ),
          ),
          Expanded(
            child: Container(
              padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 10.h),
              height: 100.w,
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(10.r),
                  bottomLeft: Radius.circular(10.r),
                ),
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Column(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      RichText(
                        text: TextSpan(
                          text: name,
                          style: TextStyle(
                              color: Colors.black,
                              fontSize: 13.sp,
                              fontWeight: FontWeight.w500),
                          children: [
                            TextSpan(text: '  '),
                            TextSpan(text: '$num张'),
                          ],
                        ),
                      ),
                      Text(
                        time,
                        style:
                            TextStyle(fontSize: 11.sp, color: Colors.grey[800]),
                      ),
                      Text(
                        location,
                        style:
                            TextStyle(fontSize: 11.sp, color: Colors.grey[800]),
                      ),
                      Container(
                        padding: EdgeInsets.symmetric(
                            horizontal: 8.w, vertical: 3.h),
                        decoration: BoxDecoration(
                          border: Border.all(color: Colors.orange.shade100),
                          borderRadius: BorderRadius.circular(20.r),
                        ),
                        alignment: Alignment.center,
                        child: Text(
                          '评价影片',
                          style: TextStyle(
                              fontSize: 11.sp,
                              color: Colors.orange,
                              fontWeight: FontWeight.w600),
                        ),
                      ),
                    ],
                  ),
                  Container(
                      decoration: BoxDecoration(
                        border:
                            Border.all(color: Colors.grey.shade300, width: 2),
                        borderRadius: BorderRadius.circular(30),
                      ),
                      width: 60,
                      height: 60,
                      alignment: Alignment.center,
                      child: Stack(
                        alignment: Alignment.center,
                        children: [
                          Container(
                            decoration: BoxDecoration(
                              border: Border.all(
                                  color: Colors.grey.shade300, width: 2),
                              borderRadius: BorderRadius.circular(20.r),
                            ),
                            width: 40,
                            height: 40,
                          ),
                          Transform.rotate(
                            angle: pi / 6,
                            child: Container(
                                width: 40,
                                height: 20,
                                color: Colors.white,
                                child: Center(
                                  child: Text(
                                    '已放映',
                                    style: TextStyle(
                                        color: Colors.grey[300],
                                        fontSize: 11.sp,
                                        fontWeight: FontWeight.w900),
                                  ),
                                )),
                          )
                        ],
                      )),
                ],
              ),
            ),
          )
        ],
      ),
    );
  }
}
